package com.joysuch.wwyt.api.base.controller;

import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.exception.ApiCoreException;
import com.joysuch.wwyt.workflow.bean.LocationVerifyRecordBean;
import com.joysuch.wwyt.workflow.bean.WorkFlowSignBean;
import com.joysuch.wwyt.workflow.service.WorkFlowTaskSignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author jignwk
 * @since 2022/04/06 11:48
 */
@RestController
@RequestMapping("/api/base/location-verify")
@Api(tags = "流程引擎的数据源接口")
public class LocationVerifyController {

    @Autowired
    private WorkFlowTaskSignService workFlowTaskSignService;

    @GetMapping("detail")
    @ApiOperation(value = "获取签字位置详情")
    public ResultBean getSignatureByTaskCode(String processInsId) {
        List<LocationVerifyRecordBean> list = workFlowTaskSignService.getLocationVerifyRecordByTaskCode(processInsId);
        return ResultBean.success(list);
    }

    @PostMapping("/area")
    @ApiOperation(value = "签字位置校验")
    public ResultBean verifySignArea(@Valid @RequestBody WorkFlowSignBean signBean) {
        try {
            signBean.setNewWorkflow(true);
            return ResultBean.success(workFlowTaskSignService.verifySignArea(signBean));
        } catch (ApiCoreException e) {
            return ResultBean.fail(e.getCode(), e.getMessage());
        }
    }

    @PostMapping("/area-bluetooth")
    @ApiOperation(value = "签字位置校验-蓝牙")
    public ResultBean verifySignAreaBluetooth(@RequestBody WorkFlowSignBean signBean) {
        return ResultBean.success(workFlowTaskSignService.verifySignAreaBluetooth(signBean));
    }
}
